home *** CD-ROM | disk | FTP | other *** search
- Path: risc.sps.mot.com!not-for-mail
- From: moss@sit.sps.mot.com (Matthew Moss)
- Newsgroups: comp.lang.c++
- Subject: Incompatible function pointers?
- Date: 17 Apr 1996 14:11:33 -0500
- Organization: Motorola, Inc. -- Austin,TX
- Message-ID: <4l3fp5INN1ak@sit.sps.mot.com>
- NNTP-Posting-Host: sit.sps.mot.com
-
-
- Can anyone tell me why this won't work? All compilers I've tried complain
- about passing G::Create() into test().... I would've thought this a problem
- if they were member functions, but G::Create() is static.
-
- I couldn't easily find anything about this in the ARM or ANSI references...
- Thanks...
-
- class A {
- public:
- int x;
-
- A(int v = 0) : x(v) { }
- };
-
- class G {
- int y;
-
- G(int v = 0) : y(v) { }
-
- public:
- static G* Create(A*);
- };
-
-
- typedef void* (*CreatorFP)(A*);
-
-
- G* G::Create(A *a)
- {
- return new G(a->x);
- }
-
-
- void* test(A *a, CreatorFP cfp)
- {
- return (*cfp)(a);
- }
-
-
- void main()
- {
- A *a = new A(65);
- G *g = (G*) test(a, G::Create);
-
- delete g;
- delete a;
- }
- --
- ===============================================================================
- Matthew D Moss RISC Software, Motorola
- moss@risc.sps.mot.com http://www.mot.com/PowerPC/
-